package com.edgclub.edg.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.edgclub.edg.R;
import com.edgclub.edg.activity.UserInfoOtherActivity;
import com.edgclub.edg.model.User;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;

import java.util.ArrayList;


public class LikeAdapter extends BaseAdapter {

	private Context mContext;

	private ArrayList<User> likeUsers;

	private GlideUtils glideUtils;

	private onClickImageClickListener clickImageClickListener;
	public LikeAdapter(Context context) {
		this.mContext = context;
		this.mContext = mContext;
		glideUtils = new GlideUtils();
	}

	public onClickImageClickListener getClickImageClickListener() {
		return clickImageClickListener;
	}

	public void setClickImageClickListener(
			onClickImageClickListener clickImageClickListener) {
		this.clickImageClickListener = clickImageClickListener;
	}

	public ArrayList<User> getLikeUsers() {
		return likeUsers;
	}

	public void setLikeUsers(ArrayList<User> likeUsers) {
		this.likeUsers = likeUsers;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (null == likeUsers) {
			return 0;
		}
		return Math.min(8, likeUsers.size());
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup group) {
		holder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_user_logo_image, null);

			holder = new holder();
			holder. image = (ImageView) convertView.findViewById(R.id.image);
			holder.vip = (ImageView) convertView.findViewById(R.id.vip);
			convertView.setTag(holder);
		} else {
			holder = (holder) convertView.getTag();
		}
		final User likeUser1 = likeUsers.get(position);
		User likeUser = likeUsers.get(position);
		glideUtils.Glidde_loadCropCircleImage(mContext,likeUser.getLogo(), holder.image);
		holder.image.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent=new Intent(mContext, UserInfoOtherActivity.class);
				intent.putExtra("user",likeUser1);
				mContext.startActivity(intent);
			}
		});
		if(null!=likeUser.getUserAuth()){
			if ("-1".equals(likeUser.getUserAuth().getType())){
				holder.vip.setVisibility(View.GONE);
			}
			if("0".equals(likeUser.getUserAuth().getType())){
				holder.vip.setVisibility(View.VISIBLE);
				holder.vip.setImageResource(R.drawable.v_huan);
			}else if("1".equals(likeUser.getUserAuth().getType())){
				holder.vip.setVisibility(View.VISIBLE);
				holder.vip.setImageResource(R.drawable.v_lan);
			}
		}else{
			holder.vip.setVisibility(View.GONE);
		}
		return convertView;
	}

	class holder {
		public ImageView image,vip;
	}

	/**
	 *
	 */
	public interface onClickImageClickListener {
		public void onClick(int position, int mTopicPosition);

	}
}
